package com.example.goodpet.activity.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.example.goodpet.activity.Fragment.TipsContentFragment;
import com.example.goodpet.base.BaseFragment;
import com.example.goodpet.home.homeRecommend.bean.Tips;

import java.util.ArrayList;
import java.util.List;

public class TipsPagerAdapter extends FragmentStateAdapter {
    private List<BaseFragment> fragments;
    private Tips.ResultDTO result;

    public TipsPagerAdapter(@NonNull Fragment fragment,Tips.ResultDTO result) {
        super(fragment);
        this.result=result;
        if(fragments==null){
            fragments=new ArrayList<>();
        }
    }

    public void addFragment(TipsContentFragment fragment, int type) {
        if (fragments != null) {
            fragment.setData(result,type);
            fragments.add(fragment);

        }
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        return fragments.get(position);

    }

    @Override
    public int getItemCount() {
        return fragments.size();
    }
}
